package main

import (
	"fmt"
	"github.com/go-redis/redis"
	"strings"
	"time"
)

// 获取redis集群连接
func GetRedisClusterConnect(dsn string) (*redis.ClusterClient, error) {
	cluster := redis.NewClusterClient(&redis.ClusterOptions{
		Addrs:        strings.Split(dsn, ","),
		DialTimeout:  15 * time.Second,
		ReadTimeout:  15 * time.Second,
		WriteTimeout: 15 * time.Second,
		PoolSize:     4,
		MaxConnAge:   60 * time.Second,
	})
	if cluster.Ping().Val() != "PONG" {
		return nil, fmt.Errorf("连接异常")
	}
	return cluster, nil
}

func main() {
	// dsn := "hsbss-hkfeature-midd.hszq8.com:36244"
	dsn := "10.68.4.118:7000"
	// key := "sc:230609:50896"
	key := "us:data:reference:230609:TSLA"
	bsshqConn, err := GetRedisClusterConnect(dsn)
	if err != nil {
		fmt.Println(err)
		return
	}
	res := bsshqConn.HGetAll(key)
	fmt.Println(res.Result())
}
